{% extends 'base.html' %}
{% load static %}

{% block title %}{{ api_info.title }} - Creeps Judge{% endblock %}

{% block extra_css %}
<!-- CodeMirror CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/theme/monokai.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/fold/foldgutter.min.css">
<style>
    /* ========================================
           CSS 变量定义 - 统一管理颜色和效果
        ======================================== */
    :root {
        /* 主题色彩系统 */
        --primary-blue: 100, 150, 255;
        --secondary-blue: 0, 212, 255;
        --accent-pink: 255, 100, 150;
        --accent-green: 100, 255, 150;

        /* 背景渐变 */
        --bg-main: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
        --bg-card: linear-gradient(145deg, rgba(15, 25, 45, 0.95), rgba(25, 35, 65, 0.9));
        --bg-glass: linear-gradient(135deg, rgba(40, 50, 70, 0.4), rgba(60, 80, 120, 0.6));

        /* 阴影效果 */
        --shadow-card: 0 15px 45px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(100, 150, 255, 0.2);
        --shadow-hover: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 40px rgba(var(--primary-blue), 0.6);

        /* 过渡效果 */
        --transition-smooth: all 0.3s ease;
        --transition-bounce: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);

        /* 模糊效果 */
        --blur-light: blur(10px);
        --blur-heavy: blur(25px);
    }

    .api-container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 20px;
        color: rgba(255, 255, 255, 0.9);
        background: var(--bg-main);
        min-height: 100vh;
    }

    .api-header {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.2), rgba(var(--secondary-blue), 0.2));
        border-radius: 15px;
        padding: 30px;
        text-align: center;
        color: rgba(255, 255, 255, 0.9);
        margin-bottom: 30px;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
        backdrop-filter: var(--blur-heavy);
        border: 2px solid rgba(var(--primary-blue), 0.3);
    }

    .api-header h1 {
        color: rgba(255, 255, 255, 0.95);
        font-size: 2.5em;
        margin-bottom: 15px;
        font-weight: 700;
        transition: var(--transition-smooth);
        cursor: pointer;
        background: linear-gradient(45deg, #667eea, #764ba2);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .api-header h1:hover {
        animation: text-glow 1.5s ease-in-out infinite;
        transform: scale(1.02);
    }

    .api-header .version {
        display: inline-block;
        background: linear-gradient(45deg, #667eea, #764ba2);
        color: white;
        padding: 8px 20px;
        border-radius: 25px;
        font-size: 1em;
        margin-bottom: 20px;
        font-weight: 500;
    }

    .api-header .description {
        color: rgba(255, 255, 255, 0.8);
        font-size: 1.2em;
        line-height: 1.6;
        margin-bottom: 20px;
    }

    .nav-tabs {
        display: flex;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 15px;
        padding: 8px;
        margin-bottom: 30px;
        gap: 8px;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
        backdrop-filter: var(--blur-heavy);
        border: 2px solid rgba(var(--primary-blue), 0.3);
    }

    .nav-tab {
        flex: 1;
        padding: 15px 20px;
        text-align: center;
        background: transparent;
        border: none;
        border-radius: 10px;
        cursor: pointer;
        transition: var(--transition-smooth);
        font-size: 1.1em;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.7);
    }

    .nav-tab.active {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.8), rgba(var(--secondary-blue), 0.8));
        color: white;
        box-shadow: 0 4px 15px rgba(var(--primary-blue), 0.4);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .nav-tab:hover:not(.active) {
        background: rgba(var(--primary-blue), 0.3);
        color: rgba(255, 255, 255, 0.95);
        transform: translateY(-2px) scale(1.02);
        box-shadow: 0 8px 20px rgba(var(--primary-blue), 0.2);
        text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
    }

    .content-section {
        display: none;
    }

    .content-section.active {
        display: block;
    }

    .rules-content {
        max-width: 1200px;
        margin: 0 auto;
        padding: 40px;
        background: var(--bg-glass);
        border-radius: 20px;
        border: 1px solid rgba(var(--primary-blue), 0.2);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        backdrop-filter: var(--blur-heavy);
    }

    .rules-content h1 {
        color: white;
        text-align: center;
        margin-bottom: 30px;
        font-size: 2.5em;
        text-shadow: 0 0 20px rgba(var(--primary-blue), 0.8);
    }

    .rules-content h2 {
        color: rgba(var(--primary-blue), 1);
        border-bottom: 2px solid rgba(var(--primary-blue), 0.3);
        padding-bottom: 10px;
        margin-top: 40px;
        margin-bottom: 20px;
        text-shadow: 0 0 10px rgba(var(--primary-blue), 0.5);
    }

    .rules-content h3 {
        color: rgba(var(--secondary-blue), 1);
        margin-top: 30px;
        margin-bottom: 15px;
    }

    .rules-content p,
    .rules-content li {
        color: rgba(255, 255, 255, 0.9);
        line-height: 1.6;
        margin-bottom: 10px;
    }

    .rules-content table {
        width: 100%;
        border-collapse: collapse;
        margin: 20px 0;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 10px;
        overflow: hidden;
    }

    .rules-content th,
    .rules-content td {
        padding: 12px 15px;
        text-align: left;
        border-bottom: 1px solid rgba(var(--primary-blue), 0.2);
        color: rgba(255, 255, 255, 0.9);
    }

    .rules-content th {
        background: rgba(var(--primary-blue), 0.3);
        color: white;
        font-weight: 600;
    }

    .rules-content code {
        background: rgba(0, 0, 0, 0.5);
        padding: 2px 6px;
        border-radius: 4px;
        color: rgba(var(--accent-green), 1);
        font-family: 'Courier New', monospace;
    }

    .rules-content pre {
        background: rgba(0, 0, 0, 0.6);
        padding: 20px;
        border-radius: 10px;
        overflow-x: auto;
        border-left: 4px solid rgba(var(--primary-blue), 0.8);
    }

    .rules-content pre code {
        background: none;
        padding: 0;
        color: rgba(255, 255, 255, 0.9);
    }

    .rules-content ol,
    .rules-content ul {
        padding-left: 30px;
    }

    .rules-content hr {
        border: none;
        height: 2px;
        background: linear-gradient(90deg, transparent, rgba(var(--primary-blue), 0.5), transparent);
        margin: 40px 0;
    }

    .api-category {
        margin-bottom: 40px;
        background: var(--bg-glass);
        border-radius: 20px;
        overflow: hidden;
        border: 1px solid rgba(var(--primary-blue), 0.2);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    }

    .category-header {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.8), rgba(var(--secondary-blue), 0.6));
        padding: 20px;
        cursor: pointer;
        transition: var(--transition-smooth);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .category-header:hover {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.95), rgba(var(--secondary-blue), 0.8));
        box-shadow: 0 0 30px rgba(var(--primary-blue), 0.6), 0 8px 25px rgba(0, 0, 0, 0.3);
        transform: translateY(-3px);
        animation: category-glow 1.5s ease-in-out infinite;
    }

    .category-title {
        display: flex;
        align-items: center;
        gap: 15px;
    }

    .category-title .category-icon {
        font-size: 24px;
        color: white;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }

    .category-title h3 {
        color: white;
        margin: 0;
        font-size: 1.4em;
        font-weight: 600;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
        transition: all 0.3s ease;
    }

    .category-header:hover .category-title h3 {
        animation: text-glow 1.5s ease-in-out infinite;
        transform: scale(1.05);
    }

    .api-count {
        background: rgba(255, 255, 255, 0.2);
        padding: 4px 12px;
        border-radius: 15px;
        font-size: 0.8em;
        color: white;
        margin-left: 10px;
        transition: var(--transition-smooth);
    }

    .category-header:hover .api-count {
        background: rgba(255, 255, 255, 0.3);
        transform: scale(1.1);
        animation: floating 2s ease-in-out infinite;
    }

    .toggle-icon {
        color: white;
        font-size: 18px;
        transition: transform 0.3s ease;
    }

    .category-header.collapsed .toggle-icon {
        transform: rotate(-90deg);
    }

    .api-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 20px;
        padding: 25px;
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.2), rgba(10, 20, 40, 0.3));
        border-radius: 0 0 20px 20px;
    }

    /* ========================================
           通用卡牌基础样式 - 适用于所有卡牌类型
           包含：基础布局、悬停效果、动画等
        ======================================== */
    .base-card {
        position: relative;
        background: var(--bg-card);
        border: 2px solid transparent;
        border-radius: 20px;
        padding: 0;
        margin-bottom: 20px;
        cursor: pointer;
        transition: var(--transition-bounce);
        overflow: hidden;
        backdrop-filter: var(--blur-heavy);
        box-shadow: var(--shadow-card), inset 0 2px 0 rgba(255, 255, 255, 0.15), inset 0 -2px 0 rgba(0, 0, 0, 0.1);
        display: flex;
        flex-direction: column;
    }

    /* API卡牌特定样式 */
    .api-card {
        height: 160px;
        min-height: 160px;
    }

    .base-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(45deg,
                rgba(var(--primary-blue), 0.1) 0%,
                rgba(var(--secondary-blue), 0.05) 50%,
                rgba(var(--accent-pink), 0.1) 100%);
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }

    .base-card::after {
        content: '';
        position: absolute;
        top: -2px;
        left: -2px;
        right: -2px;
        bottom: -2px;
        background: linear-gradient(45deg,
                rgba(var(--primary-blue), 0.3),
                rgba(var(--secondary-blue), 0.2),
                rgba(var(--accent-pink), 0.3),
                rgba(var(--accent-green), 0.2));
        border-radius: 22px;
        opacity: 0;
        z-index: -1;
        transition: opacity 0.3s ease;
        animation: border-glow 3s ease-in-out infinite;
    }

    .base-card:hover::before {
        opacity: 1;
    }

    .base-card:hover::after {
        opacity: 1;
    }

    .base-card:hover {
        transform: translateY(-15px) scale(1.05) rotateX(5deg);
        box-shadow: var(--shadow-hover),
            0 0 80px rgba(var(--primary-blue), 0.3),
            0 0 120px rgba(var(--primary-blue), 0.1),
            inset 0 2px 0 rgba(255, 255, 255, 0.3),
            inset 0 -2px 0 rgba(0, 0, 0, 0.2);
        border: 2px solid rgba(var(--primary-blue), 0.9);
        animation: card-glow-pulse 2s ease-in-out infinite;
    }

    .base-card:hover .card-hover-hint {
        opacity: 1;
        transform: translateY(2px);
        animation: floating 2s ease-in-out infinite;
    }

    .base-card:active {
        transform: translateY(-8px) scale(1.01);
        transition: all 0.1s ease;
    }

    /* ========================================
           可复用的卡牌布局组件系统
           适用于：API接口、数据类型、示例代码等所有卡牌
           使用方法：
           1. .card-header-section - 顶部区域（图标+标题横向布局）
           2. .card-body-section - 主体区域（描述文字）
           3. .card-hover-hint - 悬停提示（右上角）
        ======================================== */
    .card-header-section {
        padding: 20px 20px 10px 20px;
        display: flex;
        align-items: center;
        gap: 12px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .card-body-section {
        padding: 15px 20px 20px 20px;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }

    .card-icon {
        width: 40px;
        height: 40px;
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.4), rgba(var(--secondary-blue), 0.3));
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: rgba(100, 200, 255, 0.95);
        font-size: 1.2em;
        flex-shrink: 0;
        box-shadow: 0 6px 15px rgba(var(--primary-blue), 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.2);
        border: 1px solid rgba(var(--primary-blue), 0.3);
    }

    .card-title {
        color: rgba(255, 255, 255, 0.98);
        font-size: 1.1em;
        margin: 0;
        font-weight: 600;
        text-shadow: 0 0 12px rgba(255, 255, 255, 0.4);
        letter-spacing: 0.3px;
        line-height: 1.3;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        transition: var(--transition-smooth);
    }

    .card-title:hover {
        animation: text-glow 2s ease-in-out infinite;
        color: rgba(255, 255, 255, 1.0);
    }

    .card-description {
        color: rgba(255, 255, 255, 0.7);
        margin: 0;
        line-height: 1.4;
        font-size: 0.85em;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }

    .card-hover-hint {
        position: absolute;
        top: 12px;
        right: 15px;
        color: rgba(var(--primary-blue), 0.8);
        font-size: 0.7em;
        opacity: 0;
        transition: var(--transition-smooth);
        display: flex;
        align-items: center;
        gap: 4px;
        background: rgba(var(--primary-blue), 0.1);
        padding: 4px 8px;
        border-radius: 12px;
        border: 1px solid rgba(var(--primary-blue), 0.2);
        backdrop-filter: var(--blur-light);
        font-weight: 500;
    }

    .api-card:hover .card-hover-hint {
        opacity: 1;
        transform: translateY(2px);
        animation: floating 2s ease-in-out infinite;
    }

    .api-card .syntax {
        background: rgba(0, 0, 0, 0.3);
        padding: 10px;
        border-radius: 8px;
        font-family: 'Courier New', monospace;
        font-size: 0.9em;
        color: rgba(var(--accent-green), 0.9);
        border: 1px solid rgba(var(--primary-blue), 0.2);
        position: relative;
        overflow: hidden;
    }

    /* 游戏化特效增强 */
    .card-icon:hover {
        transform: scale(1.2) rotate(10deg) translateZ(10px);
        box-shadow: 0 15px 35px rgba(var(--primary-blue), 0.5),
            inset 0 1px 0 rgba(255, 255, 255, 0.4),
            0 0 25px rgba(var(--primary-blue), 0.4);
    }

    @keyframes border-glow {

        0%,
        100% {
            background: linear-gradient(45deg,
                    rgba(100, 150, 255, 0.3),
                    rgba(0, 212, 255, 0.2),
                    rgba(255, 100, 150, 0.3),
                    rgba(100, 255, 150, 0.2));
        }

        50% {
            background: linear-gradient(45deg,
                    rgba(255, 100, 150, 0.3),
                    rgba(100, 255, 150, 0.2),
                    rgba(100, 150, 255, 0.3),
                    rgba(0, 212, 255, 0.2));
        }
    }

    @keyframes card-glow-pulse {

        0%,
        100% {
            box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6),
                0 0 40px rgba(100, 150, 255, 0.6),
                0 0 80px rgba(100, 150, 255, 0.3),
                0 0 120px rgba(100, 150, 255, 0.1);
        }

        50% {
            box-shadow: 0 35px 90px rgba(0, 0, 0, 0.7),
                0 0 50px rgba(100, 150, 255, 0.8),
                0 0 100px rgba(100, 150, 255, 0.4),
                0 0 150px rgba(100, 150, 255, 0.2);
        }
    }

    @keyframes category-glow {

        0%,
        100% {
            box-shadow: 0 0 30px rgba(100, 150, 255, 0.6), 0 8px 25px rgba(0, 0, 0, 0.3);
        }

        50% {
            box-shadow: 0 0 40px rgba(100, 150, 255, 0.8), 0 12px 35px rgba(0, 0, 0, 0.4);
        }
    }

    @keyframes detail-card-glow {

        0%,
        100% {
            box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 20px rgba(var(--primary-blue), 0.3);
        }

        50% {
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 0 30px rgba(var(--primary-blue), 0.5);
        }
    }

    @keyframes floating {

        0%,
        100% {
            transform: translateY(0px);
        }

        50% {
            transform: translateY(-5px);
        }
    }

    @keyframes text-glow {

        0%,
        100% {
            text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
        }

        50% {
            text-shadow: 0 0 15px rgba(255, 255, 255, 0.6), 0 0 25px rgba(var(--primary-blue), 0.4);
        }
    }

    .card-icon {
        /* 移除了动画效果 */
    }

    /* 简化的详情卡牌样式 - 用于列表项 */
    .simple-detail-card {
        background: rgba(255, 255, 255, 0.05);
        border-radius: 10px;
        padding: 18px;
        margin-bottom: 12px;
        border-left: 3px solid rgba(var(--primary-blue), 0.8);
        transition: var(--transition-smooth);
    }

    .simple-detail-card:hover {
        background: rgba(255, 255, 255, 0.12);
        border-left-color: rgba(var(--primary-blue), 1);
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 20px rgba(var(--primary-blue), 0.3);
        transform: translateX(8px) translateY(-2px);
        animation: detail-card-glow 2s ease-in-out infinite;
    }

    .api-detail-title {
        color: rgba(255, 255, 255, 0.95);
        font-size: 1.2em;
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .api-detail-title i {
        color: rgba(var(--primary-blue), 0.8);
    }

    /* 折叠功能样式 */
    .collapsible {
        background: rgba(var(--primary-blue), 0.1);
        color: rgba(255, 255, 255, 0.9);
        cursor: pointer;
        padding: 12px 16px;
        width: 100%;
        border: none;
        text-align: left;
        outline: none;
        font-size: 1em;
        border-radius: 8px;
        margin: 8px 0;
        transition: var(--transition-smooth);
        display: flex;
        align-items: center;
        justify-content: space-between;
        backdrop-filter: blur(5px);
        border: 1px solid rgba(var(--primary-blue), 0.2);
    }

    .collapsible:hover {
        background: rgba(var(--primary-blue), 0.3);
        border-color: rgba(var(--primary-blue), 0.6);
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(var(--primary-blue), 0.2);
        text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    }

    .collapsible.active {
        background: rgba(var(--primary-blue), 0.25);
        border-color: rgba(var(--primary-blue), 0.5);
    }

    .collapsible-icon {
        transition: transform 0.3s ease;
        font-size: 0.8em;
    }

    .collapsible-icon {
        transform: rotate(90deg);
        transition: transform 0.3s ease;
    }

    .collapsible.collapsed .collapsible-icon {
        transform: rotate(0deg);
    }

    .collapsible-content {
        padding: 16px;
        max-height: 1000px;
        overflow: hidden;
        transition: max-height 0.3s ease;
        background: rgba(0, 0, 0, 0.1);
        border-radius: 0 0 8px 8px;
        margin-top: -8px;
    }

    .collapsible-content.collapsed {
        padding: 0;
        max-height: 0;
    }

    .api-detail-section {
        margin: 16px 0;
    }

    .api-detail-section h4 {
        color: rgba(255, 255, 255, 0.95);
        margin: 0 0 8px 0;
        font-size: 1em;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .parameter-list {
        list-style: none;
        padding: 0;
        margin: 8px 0;
    }

    .parameter-list li {
        background: rgba(255, 255, 255, 0.05);
        padding: 8px 12px;
        margin: 4px 0;
        border-radius: 6px;
        border-left: 3px solid rgba(100, 150, 255, 0.5);
        color: rgba(255, 255, 255, 0.8);
        font-size: 0.9em;
    }

    .required {
        background: rgba(255, 100, 100, 0.2);
        color: rgba(255, 150, 150, 0.9);
        padding: 2px 6px;
        border-radius: 4px;
        font-size: 0.8em;
        margin-left: 8px;
    }

    /* 通用详情卡牌样式 - 用于模态框内容 */
    .detail-card {
        background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(100, 150, 255, 0.05) 100%);
        border: 1px solid rgba(100, 150, 255, 0.3);
        border-radius: 12px;
        padding: 20px;
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        cursor: pointer;
        backdrop-filter: blur(10px);
        color: rgba(255, 255, 255, 0.9);
        position: relative;
        overflow: hidden;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2), 0 0 10px rgba(100, 150, 255, 0.1);
    }

    .detail-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
        transition: left 0.5s ease;
    }

    .detail-card:hover {
        transform: translateY(-8px) scale(1.02);
        border-color: rgba(100, 150, 255, 0.8);
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4),
            0 0 30px rgba(100, 150, 255, 0.3),
            0 0 60px rgba(100, 150, 255, 0.15);
        animation: detail-card-shimmer 2s ease-in-out infinite;
    }

    .detail-card:hover::before {
        left: 100%;
    }

    .api-card h4 {
        color: rgba(255, 255, 255, 0.95);
        font-size: 1.3em;
        margin-bottom: 12px;
        display: flex;
        align-items: center;
        font-weight: 600;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .api-card h4 i {
        margin-right: 10px;
        color: rgba(100, 150, 255, 0.8);
        text-shadow: 0 0 8px rgba(100, 150, 255, 0.4);
    }

    .api-card .syntax {
        background: rgba(100, 150, 255, 0.1);
        border: 1px solid rgba(100, 150, 255, 0.3);
        color: rgba(100, 200, 255, 0.9);
        padding: 12px 15px;
        border-radius: 8px;
        font-family: 'Courier New', monospace;
        font-size: 0.9em;
        margin: 15px 0;
        overflow-x: auto;
        backdrop-filter: blur(5px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .api-card .description {
        color: rgba(255, 255, 255, 0.8);
        line-height: 1.6;
        margin-bottom: 15px;
        font-size: 0.95em;
    }

    .api-card .returns {
        display: inline-block;
        background: rgba(40, 167, 69, 0.1);
        border: 1px solid rgba(40, 167, 69, 0.3);
        color: rgba(80, 200, 120, 0.9);
        padding: 6px 12px;
        border-radius: 15px;
        font-size: 0.85em;
        font-weight: 500;
        backdrop-filter: blur(5px);
        text-shadow: 0 0 8px rgba(80, 200, 120, 0.3);
    }

    /* 通用专业卡牌样式 - 用于数据类型和示例 */
    .professional-card {
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.8) 0%, rgba(30, 30, 60, 0.9) 100%);
        backdrop-filter: blur(15px);
        border: 1px solid rgba(100, 150, 255, 0.3);
        border-radius: 15px;
        padding: 25px;
        margin-bottom: 25px;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2), 0 0 15px rgba(100, 150, 255, 0.1);
        color: rgba(255, 255, 255, 0.9);
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .professional-card:hover {
        transform: translateY(-8px) scale(1.02);
        border-color: rgba(100, 150, 255, 0.8);
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4),
            0 0 35px rgba(100, 150, 255, 0.4),
            0 0 70px rgba(100, 150, 255, 0.2);
        animation: professional-card-pulse 1.5s ease-in-out infinite;
    }

    /* 数据类型卡牌 - 绿色主题 */
    .data-type-card {
        --theme-primary: 40, 167, 69;
        --theme-secondary: 76, 175, 80;
        --theme-accent: 139, 195, 74;
        --theme-quaternary: 102, 187, 106;
    }

    .data-type-card h4 {
        color: rgba(255, 255, 255, 0.95);
        font-size: 1.3em;
        margin-bottom: 15px;
        display: flex;
        align-items: center;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .data-type-card h4 i {
        margin-right: 10px;
        color: rgba(40, 167, 69, 0.8);
        text-shadow: 0 0 8px rgba(40, 167, 69, 0.4);
    }

    .properties-table,
    .methods-table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 15px;
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(30, 30, 60, 0.8) 100%);
        border-radius: 12px;
        overflow: hidden;
        backdrop-filter: blur(15px);
        border: 1px solid rgba(100, 150, 255, 0.3);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }

    .properties-table th,
    .properties-table td,
    .methods-table th,
    .methods-table td {
        padding: 12px;
        text-align: left;
        border-bottom: 1px solid rgba(100, 150, 255, 0.2);
    }

    .properties-table th,
    .methods-table th {
        background: linear-gradient(135deg, rgba(100, 150, 255, 0.8), rgba(0, 212, 255, 0.8));
        font-weight: 600;
        color: white;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .properties-table td,
    .methods-table td {
        color: rgba(255, 255, 255, 0.9);
    }

    .properties-table tr:hover,
    .methods-table tr:hover {
        background: rgba(100, 150, 255, 0.2);
        transform: translateX(5px);
        box-shadow: 0 4px 15px rgba(100, 150, 255, 0.2);
        transition: all 0.3s ease;
    }

    .properties-table td:hover,
    .methods-table td:hover {
        color: rgba(255, 255, 255, 1.0);
        text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    }

    .type-badge {
        background: rgba(30, 150, 243, 0.2);
        color: rgba(100, 200, 255, 0.9);
        border: 1px solid rgba(30, 150, 243, 0.4);
        padding: 4px 10px;
        border-radius: 12px;
        font-size: 0.8em;
        font-family: 'Courier New', monospace;
        backdrop-filter: blur(5px);
        text-shadow: 0 0 8px rgba(100, 200, 255, 0.3);
        transition: all 0.3s ease;
        cursor: pointer;
    }

    .type-badge:hover {
        background: rgba(30, 150, 243, 0.4);
        color: rgba(100, 200, 255, 1.0);
        border-color: rgba(30, 150, 243, 0.8);
        transform: scale(1.1);
        box-shadow: 0 0 15px rgba(100, 200, 255, 0.4);
        text-shadow: 0 0 12px rgba(100, 200, 255, 0.5);
    }

    /* 示例卡牌 - 橙色主题 */
    .example-card {
        --theme-primary: 255, 152, 0;
        --theme-secondary: 255, 193, 7;
        --theme-accent: 255, 235, 59;
        --theme-quaternary: 255, 183, 77;
    }

    /* 新增：下载卡片和按钮样式 */
    .download-card {
        height: 200px;
        min-height: 200px;
    }

    .download-link {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 10px 16px;
        border-radius: 8px;
        text-decoration: none;
        color: white;
        font-weight: 500;
        margin-top: 10px;
        transition: all 0.3s ease;
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .lua-link {
        background: linear-gradient(135deg, #4A90E2, #357ABD);
    }

    .python-link {
        background: linear-gradient(135deg, #4A90E2, #357ABD);
    }

    .ts-link {
        background: linear-gradient(135deg, #3178C6, #2B6CB0);
    }

    .js-link {
        background: linear-gradient(135deg, #4A90E2, #357ABD);
        color: white !important;
    }

    .download-link:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
        border-color: rgba(255, 255, 255, 0.4);
        color: white;
    }

    .js-link:hover {
        color: white !important;
    }

    .section-header {
        text-align: center;
        margin-bottom: 30px;
        padding: 20px;
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.1), rgba(var(--secondary-blue), 0.05));
        border-radius: 15px;
        border: 1px solid rgba(var(--primary-blue), 0.2);
    }

    .section-header h2 {
        color: rgba(255, 255, 255, 0.95);
        font-size: 1.8em;
        margin-bottom: 10px;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .section-header p {
        color: rgba(255, 255, 255, 0.7);
        font-size: 1.1em;
        margin: 0;
    }

    .example-card h4 {
        color: rgba(255, 255, 255, 0.95);
        font-size: 1.2em;
        margin-bottom: 10px;
        display: flex;
        align-items: center;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .example-card h4 i {
        margin-right: 10px;
        color: rgba(255, 152, 0, 0.8);
        text-shadow: 0 0 8px rgba(255, 152, 0, 0.4);
    }

    .example-card p {
        color: rgba(255, 255, 255, 0.8);
    }

    .code-block {
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(20, 20, 40, 0.95) 100%);
        color: rgba(255, 255, 255, 0.9);
        padding: 20px;
        border-radius: 12px;
        border: 1px solid rgba(100, 150, 255, 0.3);
        font-family: 'Courier New', monospace;
        font-size: 0.9em;
        line-height: 1.6;
        overflow-x: auto;
        margin-top: 15px;
        position: relative;
        backdrop-filter: blur(10px);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 10px rgba(100, 150, 255, 0.1);
        transition: all 0.3s ease;
    }

    .code-block:hover {
        border-color: rgba(100, 150, 255, 0.6);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4), 0 0 20px rgba(100, 150, 255, 0.2);
        transform: translateY(-2px);
    }

    .code-block pre {
        margin: 0;
        padding: 0;
        background: transparent;
        border: none;
        color: inherit;
        font-family: inherit;
        font-size: inherit;
        line-height: inherit;
    }

    .copy-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        background: linear-gradient(135deg, rgba(100, 150, 255, 0.8), rgba(0, 212, 255, 0.8));
        border: 1px solid rgba(255, 255, 255, 0.3);
        color: white;
        padding: 6px 12px;
        border-radius: 8px;
        cursor: pointer;
        font-size: 0.8em;
        font-weight: 600;
        transition: all 0.3s ease;
        backdrop-filter: blur(5px);
        text-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    }

    .copy-btn:hover {
        background: linear-gradient(135deg, rgba(0, 212, 255, 1), rgba(100, 150, 255, 1));
        border-color: rgba(255, 255, 255, 0.8);
        box-shadow: 0 0 25px rgba(100, 150, 255, 0.6), 0 8px 20px rgba(0, 0, 0, 0.3);
        transform: translateY(-4px) scale(1.05);
        animation: button-pulse 1s ease-in-out infinite;
    }

    /* 格式说明页签样式 */
    .format-tabs {
        display: flex;
        gap: 10px;
        margin-bottom: 20px;
        background: rgba(0, 0, 0, 0.3);
        border-radius: 10px;
        padding: 5px;
    }

    .format-tab {
        flex: 1;
        padding: 12px 20px;
        text-align: center;
        background: transparent;
        border: none;
        border-radius: 8px;
        cursor: pointer;
        transition: var(--transition-smooth);
        font-size: 1em;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.7);
    }

    .format-tab.active {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.8), rgba(var(--secondary-blue), 0.8));
        color: white;
        box-shadow: 0 4px 15px rgba(var(--primary-blue), 0.4);
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .format-tab:hover:not(.active) {
        background: rgba(var(--primary-blue), 0.3);
        color: rgba(255, 255, 255, 0.95);
        transform: translateY(-2px);
    }

    .format-content {
        display: none;
    }

    .format-content.active {
        display: block;
    }

    .markdown-content {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        padding: 20px;
        border: 1px solid rgba(var(--primary-blue), 0.2);
        color: rgba(255, 255, 255, 0.9);
        line-height: 1.6;
    }

    .markdown-content h2 {
        color: rgba(var(--primary-blue), 1);
        border-bottom: 2px solid rgba(var(--primary-blue), 0.3);
        padding-bottom: 10px;
        margin-top: 40px;
        margin-bottom: 20px;
        text-shadow: 0 0 10px rgba(var(--primary-blue), 0.5);
    }

    .markdown-content h3 {
        color: rgba(var(--secondary-blue), 1);
        margin-top: 30px;
        margin-bottom: 15px;
    }

    .markdown-content p {
        margin-bottom: 15px;
    }

    .markdown-content ul,
    .markdown-content ol {
        padding-left: 30px;
        margin-bottom: 15px;
    }

    .markdown-content li {
        margin-bottom: 8px;
    }

    .markdown-content code {
        background: rgba(0, 0, 0, 0.5);
        padding: 2px 6px;
        border-radius: 4px;
        color: rgba(var(--accent-green), 1);
        font-family: 'Courier New', monospace;
    }

    .markdown-content pre {
        background: rgba(0, 0, 0, 0.6);
        padding: 20px;
        border-radius: 10px;
        overflow-x: auto;
        border-left: 4px solid rgba(var(--primary-blue), 0.8);
        margin: 20px 0;
    }

    .markdown-content pre code {
        background: none;
        padding: 0;
        color: rgba(255, 255, 255, 0.9);
    }

    .language-selector {
        margin-bottom: 15px;
        padding: 15px;
        background: linear-gradient(135deg, rgba(100, 150, 255, 0.1), rgba(0, 212, 255, 0.05));
        border: 1px solid rgba(100, 150, 255, 0.2);
        border-radius: 10px;
        backdrop-filter: blur(10px);
    }

    .language-selector label {
        display: block;
        color: rgba(255, 255, 255, 0.9);
        font-weight: 500;
        margin-bottom: 8px;
        font-size: 0.95em;
    }

    .language-selector label i {
        color: rgba(100, 150, 255, 0.8);
        margin-right: 8px;
    }

    .language-selector select {
        width: 100%;
        padding: 10px 15px;
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.6), rgba(20, 30, 50, 0.8));
        border: 1px solid rgba(100, 150, 255, 0.3);
        border-radius: 8px;
        color: rgba(255, 255, 255, 0.9);
        font-size: 14px;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .language-selector select:focus {
        outline: none;
        border-color: rgba(100, 150, 255, 0.8);
        box-shadow: 0 0 25px rgba(100, 150, 255, 0.5), 0 4px 15px rgba(0, 0, 0, 0.2);
        transform: translateY(-2px);
    }

    .language-selector select:hover {
        border-color: rgba(100, 150, 255, 0.7);
        box-shadow: 0 0 20px rgba(100, 150, 255, 0.4);
        transform: translateY(-1px);
    }

    .language-selector select option {
        background: rgba(20, 30, 50, 0.95);
        color: rgba(255, 255, 255, 0.9);
        padding: 8px;
    }

    /* CodeMirror编辑器样式 */
    .CodeMirror {
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.9) 0%, rgba(20, 20, 40, 0.95) 100%) !important;
        color: rgba(255, 255, 255, 0.9) !important;
        border-radius: 10px !important;
        font-size: 14px !important;
        line-height: 1.5 !important;
        height: 100% !important;
        min-height: 100% !important;
    }

    .CodeMirror .CodeMirror-code {
        font-family: 'Consolas', 'Monaco', 'Courier New', monospace !important;
    }

    .CodeMirror .CodeMirror-gutters {
        background: rgba(0, 0, 0, 0.3) !important;
        border-right: 1px solid rgba(100, 150, 255, 0.3) !important;
    }

    .CodeMirror .CodeMirror-linenumber {
        color: rgba(255, 255, 255, 0.5) !important;
    }

    .CodeMirror .CodeMirror-foldgutter-open,
    .CodeMirror .CodeMirror-foldgutter-folded {
        color: rgba(100, 150, 255, 0.8) !important;
    }

    .CodeMirror .CodeMirror-foldmarker {
        background: rgba(100, 150, 255, 0.2) !important;
        border: 1px solid rgba(100, 150, 255, 0.5) !important;
        color: rgba(255, 255, 255, 0.8) !important;
    }

    /* 模态框样式 */
    .modal {
        display: none;
        position: fixed;
        z-index: 1000;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(10px);
    }

    .modal-content {
        background: linear-gradient(135deg, rgba(45, 55, 85, 0.4), rgba(35, 45, 75, 0.5));
        margin: 5% auto;
        padding: 30px;
        border: 2px solid rgba(100, 150, 255, 0.3);
        border-radius: 20px;
        width: 90%;
        max-width: 800px;
        max-height: 80vh;
        overflow-y: auto;
        position: relative;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(20px);
    }

    /* 自定义滚动条样式 */
    .modal-content::-webkit-scrollbar {
        width: 12px;
    }

    .modal-content::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.3);
        border-radius: 10px;
    }

    .modal-content::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, rgba(100, 150, 255, 0.8), rgba(0, 212, 255, 0.8));
        border-radius: 10px;
        border: 3px solid rgba(0, 0, 0, 0.3);
    }

    .modal-content::-webkit-scrollbar-thumb:hover {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 1), rgba(var(--secondary-blue), 1));
    }

    .close {
        color: rgba(255, 255, 255, 0.7);
        float: right;
        font-size: 28px;
        font-weight: bold;
        position: absolute;
        top: 15px;
        right: 20px;
        cursor: pointer;
        transition: var(--transition-smooth);
    }

    .close:hover {
        color: rgba(var(--accent-pink), 0.9);
        text-shadow: 0 0 10px rgba(var(--accent-pink), 0.5);
    }

    /* 模态框内容样式 */
    .api-detail-modal {
        color: rgba(255, 255, 255, 0.9);
    }

    .modal-header {
        display: flex;
        align-items: center;
        margin-bottom: 30px;
        padding-bottom: 20px;
        border-bottom: 2px solid rgba(var(--primary-blue), 0.3);
    }

    .api-icon {
        width: 60px;
        height: 60px;
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.8), rgba(var(--secondary-blue), 0.6));
        border-radius: 15px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 20px;
        box-shadow: 0 8px 20px rgba(var(--primary-blue), 0.3);
    }

    .api-icon i {
        color: white;
        font-size: 24px;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }

    .api-title h2 {
        color: rgba(255, 255, 255, 0.95);
        margin: 0 0 8px 0;
        font-size: 1.8em;
        text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    }

    .api-description {
        color: rgba(255, 255, 255, 0.7);
        margin: 0;
        font-size: 1.1em;
        line-height: 1.5;
    }

    .config-reference {
        color: rgba(100, 200, 255, 0.9);
        margin: 8px 0 0 0;
        font-size: 1.0em;
        line-height: 1.4;
        padding: 8px 12px;
        background: rgba(var(--primary-blue), 0.1);
        border-left: 3px solid rgba(var(--primary-blue), 0.6);
        border-radius: 0 8px 8px 0;
    }

    .config-reference i {
        margin-right: 6px;
        color: rgba(100, 200, 255, 0.8);
    }

    .modal-section {
        margin-bottom: 25px;
    }

    .modal-section h3 {
        color: rgba(var(--primary-blue), 0.9);
        font-size: 1.3em;
        margin-bottom: 15px;
        display: flex;
        align-items: center;
        gap: 10px;
        text-shadow: 0 0 8px rgba(var(--primary-blue), 0.3);
    }

    .parameters-grid {
        display: grid;
        gap: 15px;
    }

    .parameter-item {
        background: var(--bg-card);
        border: 1px solid rgba(var(--primary-blue), 0.2);
        border-radius: 12px;
        padding: 15px;
        display: grid;
        grid-template-columns: 1fr 1fr 2fr auto;
        gap: 10px;
        align-items: center;
    }

    .param-name {
        font-weight: 600;
        color: rgba(255, 255, 255, 0.9);
    }

    .param-type {
        background: rgba(var(--primary-blue), 0.2);
        color: rgba(100, 200, 255, 0.9);
        padding: 4px 8px;
        border-radius: 8px;
        font-size: 0.9em;
        text-align: center;
    }

    .param-desc {
        color: rgba(255, 255, 255, 0.7);
        font-size: 0.9em;
    }

    .param-required {
        background: rgba(var(--accent-pink), 0.2);
        color: rgba(255, 150, 150, 0.9);
        padding: 4px 8px;
        border-radius: 8px;
        font-size: 0.8em;
        text-align: center;
    }

    .return-info {
        display: flex;
        align-items: center;
    }

    .return-type {
        background: linear-gradient(135deg, rgba(var(--accent-green), 0.3), rgba(80, 200, 120, 0.2));
        border: 1px solid rgba(var(--accent-green), 0.4);
        color: rgba(80, 200, 120, 0.9);
        padding: 10px 20px;
        border-radius: 25px;
        font-size: 1.1em;
        font-weight: 500;
        text-shadow: 0 0 8px rgba(80, 200, 120, 0.3);
    }

    .config-editor-btn {
        display: inline-block;
        background: linear-gradient(135deg, rgba(var(--primary-blue), 0.8), rgba(var(--secondary-blue), 0.8));
        color: white;
        padding: 10px 20px;
        border-radius: 8px;
        text-decoration: none;
        font-size: 0.9em;
        font-weight: 500;
        transition: var(--transition-smooth);
        border: 1px solid rgba(var(--primary-blue), 0.3);
        backdrop-filter: var(--blur-light);
    }

    .config-editor-btn:hover {
        background: linear-gradient(135deg, rgba(var(--primary-blue), 1), rgba(var(--secondary-blue), 1));
        box-shadow: 0 4px 15px rgba(var(--primary-blue), 0.4);
        text-decoration: none;
        color: white;
        transform: translateY(-2px);
    }

    .mobile-menu-btn {
        display: none;
        position: fixed;
        top: 20px;
        left: 20px;
        z-index: 1001;
        background: rgba(var(--primary-blue), 0.8);
        color: white;
        border: none;
        border-radius: 8px;
        padding: 12px;
        cursor: pointer;
        backdrop-filter: var(--blur-light);
    }

    @media (max-width: 768px) {
        .api-container {
            flex-direction: column;
        }

        .api-sidebar {
            width: 100%;
            height: auto;
            position: relative;
            transform: translateX(-100%);
            transition: transform 0.3s ease;
            border-right: none;
            border-bottom: 2px solid rgba(100, 150, 255, 0.3);
        }

        .api-sidebar.open {
            transform: translateX(0);
        }

        .api-main {
            margin-left: 0;
            padding: 10px;
        }

        .api-header {
            padding: 15px;
        }

        .api-header h1 {
            font-size: 1.5em;
        }

        .mobile-menu-btn {
            display: block;
        }

        .content-section {
            padding: 16px;
        }

        .api-detail-card {
            padding: 16px;
        }

        .search-container {
            padding: 15px;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="api-container">
    <!-- API头部信息 -->
    <div class="api-header">
        <h1><i class="fas fa-code"></i> {{ api_info.title }}</h1>
        <div class="version">v{{ api_info.version }}</div>
        <p class="description">{{ api_info.description }}</p>
        {% if user.is_staff %}
        <div style="margin-top: 20px; display: flex; gap: 15px; justify-content: center; flex-wrap: wrap;">
            <a href="{% url 'api_docs:config_editor' %}" class="config-editor-btn"> <i class="fas fa-cogs"></i> 配置编辑器
            </a>
            <a href="{% url 'api_docs:map_editor' %}" class="config-editor-btn"> <i class="fas fa-map"></i> 地图编辑器
            </a>
        </div>
        {% endif %}
    </div>

    <!-- 导航标签 -->
    <div class="nav-tabs">
        <button class="nav-tab active" onclick="showSection('readme')"><i class="fas fa-code"></i> 规则</button>
        <button class="nav-tab" onclick="showSection('types')"><i class="fas fa-database"></i> 数据类型</button>
        <button class="nav-tab" onclick="showSection('formats')"><i class="fas fa-file-code"></i> 格式说明</button>
        <button class="nav-tab" onclick="showSection('download-section')"><i class="fas fa-download"></i> 代码下载</button>
    </div>

    <!-- 规则文档部分 -->
    <div id="readme" class="content-section active">
        <div class="rules-content">
            {{ rules_content|safe }}
        </div>
    </div>

    <!-- 数据类型部分 -->
    <div id="types" class="content-section">
        <!-- 类型枚举分类 -->
        {% if data_types.type_enums %}
        <div class="api-category">
            <div class="category-header" onclick="toggleCategory(event, 'type_enums')">
                <div class="category-info">
                    <div class="category-icon">
                        <i class="fas fa-list"></i>
                    </div>
                    <div class="category-details">
                        <h3>类型枚举</h3>
                        <span class="api-count">{{ data_types.type_enums|length }} 个枚举</span>
                        <p class="category-description">{{ data_types.type_enums.description }}</p>
                    </div>
                </div>
                <i class="fas fa-chevron-down toggle-icon"></i>
            </div>

            <div class="collapsible-content">
                <div class="api-grid">
                    {% for type_name, type_info in data_types.type_enums.items %}
                    {% if type_name != 'description' %}
                    <div class="game-card data-type-card base-card" onclick="showTypeModal('{{ type_name }}')"
                        data-type="{{ type_name }}">
                        <div class="card-glow"></div>
                        <div class="card-header-section">
                            <div class="card-icon">
                                <i class="fas fa-list-ul"></i>
                            </div>
                            <h4 class="card-title">{{ type_name }}</h4>
                        </div>
                        <div class="card-body-section">
                            <p class="card-description">{{ type_info.description }}</p>
                        </div>
                        <div class="card-hover-hint">
                            <i class="fas fa-mouse-pointer"></i>
                            点击查看详情
                        </div>
                        <div class="card-border"></div>
                    </div>
                    {% endif %}
                    {% endfor %}
                </div>
            </div>
        </div>
        {% endif %}

        <!-- 常量说明分类 -->
        {% if data_types.constants %}
        <div class="api-category">
            <div class="category-header" onclick="toggleCategory(event, 'constants')">
                <div class="category-info">
                    <div class="category-icon">
                        <i class="fas fa-cog"></i>
                    </div>
                    <div class="category-details">
                        <h3>常量说明</h3>
                        <span class="api-count">{{ data_types.constants|length }} 个常量</span>
                        <p class="category-description">{{ data_types.constants.description }}</p>
                    </div>
                </div>
                <i class="fas fa-chevron-down toggle-icon"></i>
            </div>

            <div class="collapsible-content">
                <div class="api-grid">
                    {% for type_name, type_info in data_types.constants.items %}
                    {% if type_name != 'description' %}
                    <div class="game-card data-type-card base-card" onclick="showTypeModal('{{ type_name }}')"
                        data-type="{{ type_name }}">
                        <div class="card-glow"></div>
                        <div class="card-header-section">
                            <div class="card-icon">
                                <i class="fas fa-hashtag"></i>
                            </div>
                            <h4 class="card-title">{{ type_name }}</h4>
                        </div>
                        <div class="card-body-section">
                            <p class="card-description">{{ type_info.description }}</p>
                        </div>
                        <div class="card-hover-hint">
                            <i class="fas fa-mouse-pointer"></i>
                            点击查看详情
                        </div>
                        <div class="card-border"></div>
                    </div>
                    {% endif %}
                    {% endfor %}
                </div>
            </div>
        </div>
        {% endif %}

        <!-- 实体类型分类 -->
        {% if data_types.entity_types %}
        <div class="api-category">
            <div class="category-header" onclick="toggleCategory(event, 'entity_types')">
                <div class="category-info">
                    <div class="category-icon">
                        <i class="fas fa-cube"></i>
                    </div>
                    <div class="category-details">
                        <h3>实体类型</h3>
                        <span class="api-count">{{ data_types.entity_types|length }} 个实体</span>
                        <p class="category-description">{{ data_types.entity_types.description }}</p>
                    </div>
                </div>
                <i class="fas fa-chevron-down toggle-icon"></i>
            </div>

            <div class="collapsible-content">
                <div class="api-grid">
                    {% for type_name, type_info in data_types.entity_types.items %}
                    {% if type_name != 'description' %}
                    <div class="game-card data-type-card base-card" onclick="showTypeModal('{{ type_name }}')"
                        data-type="{{ type_name }}">
                        <div class="card-glow"></div>
                        <div class="card-header-section">
                            <div class="card-icon">
                                <i class="fas fa-cube"></i>
                            </div>
                            <h4 class="card-title">{{ type_name }}</h4>
                        </div>
                        <div class="card-body-section">
                            <p class="card-description">{{ type_info.description }}</p>
                        </div>
                        <div class="card-hover-hint">
                            <i class="fas fa-mouse-pointer"></i>
                            点击查看详情
                        </div>
                        <div class="card-border"></div>
                    </div>
                    {% endif %}
                    {% endfor %}
                </div>
            </div>
        </div>
        {% endif %}
    </div>

    <!-- 数据类型详情模态框 -->
    <div id="typeModal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeTypeModal()">&times;</span>
            <div id="typeDetailContent">
                <!-- 数据类型详情将通过JavaScript动态加载 -->
            </div>
        </div>
    </div>


    <!-- 格式说明部分 -->
    <div id="formats" class="content-section">
        <div class="rules-content">
            <h1><i class="fas fa-file-code"></i> 输入输出格式说明</h1>

            <!-- 格式页签导航 -->
            <div class="format-tabs" style="margin-bottom: 30px;">
                <button class="format-tab active" onclick="showFormatSection('input-format')"><i class="fas fa-arrow-down"></i> 输入格式</button>
                <button class="format-tab" onclick="showFormatSection('output-format')"><i class="fas fa-arrow-up"></i> 输出格式</button>
            </div>

            <!-- 输入格式内容 -->
            <div id="input-format" class="format-content active">
                <div class="d-flex justify-content-between align-items-center mb-2">
                    <p class="text-muted mb-0">游戏引擎传递给AI程序的数据格式</p>
                    <div class="btn-group btn-group-sm" role="group">
                        <button type="button" class="btn btn-outline-secondary" onclick="foldAllCode('input')" title="折叠所有代码块">
                            <i class="fas fa-compress-alt"></i> 全部折叠
                        </button>
                        <button type="button" class="btn btn-outline-secondary" onclick="unfoldAllCode('input')" title="展开所有代码块">
                            <i class="fas fa-expand-alt"></i> 全部展开
                        </button>
                    </div>
                </div>
                <div id="input-format-editor" style="height: 70vh; border: 1px solid rgba(100, 150, 255, 0.3); border-radius: 10px;"></div>
            </div>

            <!-- 输出格式内容 -->
            <div id="output-format" class="format-content">
                <div class="d-flex justify-content-between align-items-center mb-2">
                    <p class="text-muted mb-0">AI程序需要返回给游戏引擎的命令格式</p>
                    <div class="btn-group btn-group-sm" role="group">
                        <button type="button" class="btn btn-outline-secondary" onclick="foldAllCode('output')" title="折叠所有代码块">
                            <i class="fas fa-compress-alt"></i> 全部折叠
                        </button>
                        <button type="button" class="btn btn-outline-secondary" onclick="unfoldAllCode('output')" title="展开所有代码块">
                            <i class="fas fa-expand-alt"></i> 全部展开
                        </button>
                    </div>
                </div>
                <div id="output-format-editor" style="height: 70vh; border: 1px solid rgba(100, 150, 255, 0.3); border-radius: 10px;"></div>
            </div>
        </div>
    </div>

    <!-- 新增：下载区域 -->
    <div id="download-section" class="content-section">
        <div class="section-header">
            <h2><i class="fas fa-download"></i> 编程语言模板下载</h2>
            <p>下载完整的编程语言模板包，快速开始AI开发</p>
        </div>

        <div class="api-grid">
            <div class="base-card download-card">
                <div class="card-header-section">
                    <div class="card-icon">
                        <i class="fab fa-python"></i>
                    </div>
                    <h3 class="card-title">Python 模板包</h3>
                </div>
                <div class="card-body-section">
                    <p class="card-description">包含完整的Python项目结构、main.py、game.py和API文件</p>
                    <a href="{% url 'api_docs:download_template' 'python' %}" class="download-link python-link">
                        <i class="fas fa-download"></i> 下载 Python 模板
                    </a>
                </div>
            </div>

            <div class="base-card download-card">
                <div class="card-header-section">
                    <div class="card-icon">
                        <i class="fab fa-js-square"></i>
                    </div>
                    <h3 class="card-title">JavaScript 模板包</h3>
                </div>
                <div class="card-body-section">
                    <p class="card-description">包含完整的JavaScript项目结构、main.js、game.js和API文件</p>
                    <a href="{% url 'api_docs:download_template' 'javascript' %}" class="download-link js-link">
                        <i class="fas fa-download"></i> 下载 JavaScript 模板
                    </a>
                </div>
            </div>

            <div class="base-card download-card">
                <div class="card-header-section">
                    <div class="card-icon">
                        <i class="fas fa-file-code"></i>
                    </div>
                    <h3 class="card-title">TypeScript 模板包</h3>
                </div>
                <div class="card-body-section">
                    <p class="card-description">包含完整的TypeScript项目结构、main.ts、game.ts和API文件</p>
                    <a href="{% url 'api_docs:download_template' 'typescript' %}" class="download-link ts-link">
                        <i class="fas fa-download"></i> 下载 TypeScript 模板
                    </a>
                </div>
            </div>

            <div class="base-card download-card">
                <div class="card-header-section">
                    <div class="card-icon">
                        <i class="fas fa-code"></i>
                    </div>
                    <h3 class="card-title">Lua 模板包</h3>
                </div>
                <div class="card-body-section">
                    <p class="card-description">包含完整的Lua项目结构、main.lua、game.lua和API文件</p>
                    <a href="{% url 'api_docs:download_template' 'lua' %}" class="download-link lua-link">
                        <i class="fas fa-download"></i> 下载 Lua 模板
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // 初始化全局配置数据
    window.apiConfig = {{ config | safe }};
    window.apiExamples = {{ examples | safe }};

    // 切换侧边栏显示/隐藏（移动端）
    function toggleSidebar() {
        const sidebar = document.getElementById('sidebar');
        sidebar.classList.toggle('open');
    }

    // 切换分类折叠
    function toggleCategory(event, categoryId) {
        const categoryElement = event.target.closest('.category-header');
        const content = categoryElement.nextElementSibling;

        categoryElement.classList.toggle('collapsed');
        if (content) {
            content.classList.toggle('collapsed');
        }
    }

    // 显示数据类型详情模态框
    function showTypeModal(typeName) {
        const modal = document.getElementById('typeModal');
        const content = document.getElementById('typeDetailContent');

        // 获取数据类型数据
        const typeData = getTypeData(typeName);

        // 生成模态框内容
        content.innerHTML = `
                <div class="api-detail-modal">
                    <div class="modal-header">
                        <div class="api-icon">
                            <i class="fas fa-cube"></i>
                        </div>
                        <div class="api-title">
                            <h2>${typeData.name}</h2>
                            <p class="api-description">${typeData.description}</p>
                            ${typeData.config_description ? `<p class="config-reference"><i class="fas fa-link"></i> ${typeData.config_description}</p>` : ''}
                        </div>
                    </div>

                    ${typeData.values && typeData.values.length > 0 ? `
                    <div class="modal-section">
                        <h3><i class="fas fa-list-ul"></i> 枚举值</h3>
                        <div class="parameters-grid">
                            ${typeData.values.map(value => `
                                <div class="parameter-item">
                                    <div class="param-name">${value.name}</div>
                                    <div class="param-type">${value.value}</div>
                                    <div class="param-desc">${value.description}</div>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                    ` : ''}

                    ${typeData.constants && typeData.constants.length > 0 ? `
                    <div class="modal-section">
                        <h3><i class="fas fa-hashtag"></i> 常量</h3>
                        <div class="parameters-grid">
                            ${typeData.constants.map(constant => `
                                <div class="parameter-item">
                                    <div class="param-name">${constant.name}</div>
                                    <div class="param-type">${constant.value}</div>
                                    <div class="param-desc">${constant.description}</div>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                    ` : ''}

                    ${typeData.properties && typeData.properties.length > 0 ? `
                    <div class="modal-section">
                        <h3><i class="fas fa-list"></i> 属性</h3>
                        <div class="parameters-grid">
                            ${typeData.properties.map(prop => `
                                <div class="parameter-item">
                                    <div class="param-name">${prop.name}</div>
                                    <div class="param-type">${prop.value}</div>
                                    <div class="param-desc">${prop.description}</div>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                    ` : ''}

                    ${typeData.methods && typeData.methods.length > 0 ? `
                    <div class="modal-section">
                        <h3><i class="fas fa-cogs"></i> 方法</h3>
                        <div class="parameters-grid">
                            ${typeData.methods.map(method => `
                                <div class="parameter-item">
                                    <div class="param-name">${method.name}</div>
                                    <div class="param-type">${method.parameters} → ${method.returns}</div>
                                    <div class="param-desc">${method.description}</div>
                                </div>
                            `).join('')}
                        </div>
                    </div>
                    ` : ''}
                </div>
            `;

        modal.style.display = 'block';
    }

    // 关闭数据类型模态框
    function closeTypeModal() {
        const modal = document.getElementById('typeModal');
        modal.style.display = 'none';
    }

    // 点击模态框外部关闭
    window.onclick = function (event) {
        const apiModal = document.getElementById('apiModal');
        const typeModal = document.getElementById('typeModal');
        const exampleModal = document.getElementById('exampleModal');

        if (event.target === apiModal) {
            closeModal();
        } else if (event.target === typeModal) {
            closeTypeModal();
        } else if (event.target === exampleModal) {
            closeExampleModal();
        }
    }

    // 按ESC键关闭模态框
    document.addEventListener('keydown', function (event) {
        if (event.key === 'Escape') {
            closeModal();
            closeTypeModal();
            closeExampleModal();
        }
    });

    // 获取数据类型数据（从配置中获取真实数据）
    function getTypeData(typeName) {
        const config = window.apiConfig;
        const dataTypes = config.data_types;

        // 在三个分类中查找类型
        let typeData = null;

        // 查找类型枚举
        if (dataTypes.type_enums && dataTypes.type_enums[typeName]) {
            typeData = dataTypes.type_enums[typeName];
        }
        // 查找常量说明
        else if (dataTypes.constants && dataTypes.constants[typeName]) {
            typeData = dataTypes.constants[typeName];
        }
        // 查找实体类型
        else if (dataTypes.entity_types && dataTypes.entity_types[typeName]) {
            typeData = dataTypes.entity_types[typeName];
        }

        if (!typeData) {
            return {
                name: typeName,
                description: `${typeName} 数据类型未找到`,
                properties: [],
                methods: []
            };
        }

        return {
            name: typeName,
            description: typeData.description || `${typeName} 数据类型`,
            properties: typeData.properties || [],
            methods: typeData.methods || [],
            values: typeData.values || [],
            constants: typeData.constants || []
        };
    }

    function showSection(sectionId) {
        // 隐藏所有内容区域
        document.querySelectorAll('.content-section').forEach(section => {
            section.classList.remove('active');
        });

        // 显示选中的内容区域
        const targetSection = document.getElementById(sectionId);
        if (targetSection) {
            targetSection.classList.add('active');
        }

        // 更新导航标签状态
        document.querySelectorAll('.nav-tab').forEach(tab => {
            tab.classList.remove('active');
        });

        // 激活当前标签
        const activeTab = document.querySelector(`[onclick="showSection('${sectionId}')"]`);
        if (activeTab) {
            activeTab.classList.add('active');
        }

        // 当切换到格式说明页签时，刷新编辑器
        if (sectionId === 'formats') {
            setTimeout(() => {
                // 刷新输入格式编辑器
                if (window.inputFormatEditor) {
                    window.inputFormatEditor.refresh();
                }
                // 刷新输出格式编辑器
                if (window.outputFormatEditor) {
                    window.outputFormatEditor.refresh();
                }
            }, 150); // 稍微增加延迟确保DOM完全渲染
        }
    }

    function copyCode(button) {
        const codeBlock = button.nextElementSibling;
        const text = codeBlock.textContent;

        navigator.clipboard.writeText(text).then(() => {
            const originalText = button.innerHTML;
            button.innerHTML = '<i class="fas fa-check"></i> 已复制';
            button.style.background = 'rgba(40, 167, 69, 0.8)';

            setTimeout(() => {
                button.innerHTML = originalText;
                button.style.background = 'rgba(255, 255, 255, 0.2)';
            }, 2000);
        }).catch(err => {
            console.error('复制失败:', err);
            alert('复制失败，请手动复制');
        });
    }

    // 显示格式说明页签
    function showFormatSection(sectionId) {
        // 隐藏所有格式内容
        document.querySelectorAll('.format-content').forEach(section => {
            section.classList.remove('active');
        });

        // 显示目标内容
        const targetSection = document.getElementById(sectionId);
        if (targetSection) {
            targetSection.classList.add('active');
        }

        // 更新格式页签状态
        document.querySelectorAll('.format-tab').forEach(tab => {
            tab.classList.remove('active');
        });

        // 激活当前页签
        const activeTab = document.querySelector(`[onclick="showFormatSection('${sectionId}')"]`);
        if (activeTab) {
            activeTab.classList.add('active');
        }

        // 刷新编辑器显示
        setTimeout(() => {
            if (sectionId === 'input-format' && window.inputFormatEditor) {
                window.inputFormatEditor.refresh();
            } else if (sectionId === 'output-format' && window.outputFormatEditor) {
                window.outputFormatEditor.refresh();
            }
        }, 150);
    }

    // 折叠所有代码块的函数
    function foldAllCode(editorType) {
        if (editorType === 'input' && window.inputFormatEditor) {
            window.inputFormatEditor.execCommand('foldAll');
            showFoldMessage('已折叠所有代码块');
        } else if (editorType === 'output' && window.outputFormatEditor) {
            window.outputFormatEditor.execCommand('foldAll');
            showFoldMessage('已折叠所有代码块');
        }
    }

    // 展开所有代码块的函数
    function unfoldAllCode(editorType) {
        if (editorType === 'input' && window.inputFormatEditor) {
            window.inputFormatEditor.execCommand('unfoldAll');
            showFoldMessage('已展开所有代码块');
        } else if (editorType === 'output' && window.outputFormatEditor) {
            window.outputFormatEditor.execCommand('unfoldAll');
            showFoldMessage('已展开所有代码块');
        }
    }

    // 显示折叠操作提示
    function showFoldMessage(message) {
        const toast = document.createElement('div');
        toast.className = 'alert alert-success position-fixed';
        toast.style.cssText = 'top: 20px; right: 20px; z-index: 9999; min-width: 200px;';
        toast.innerHTML = `<i class="fas fa-check"></i> ${message}`;

        document.body.appendChild(toast);

        // 2秒后自动移除
        setTimeout(() => {
            if (toast.parentNode) {
                toast.parentNode.removeChild(toast);
            }
        }, 2000);
    }

    // 初始化CodeMirror编辑器
    document.addEventListener('DOMContentLoaded', function() {
        // 初始化输入格式编辑器
        window.inputFormatEditor = CodeMirror(document.getElementById('input-format-editor'), {
            value: `{{ input_format_content|safe }}`,
            mode: 'application/json',
            theme: 'monokai',
            lineNumbers: true,
            readOnly: true,
            lineWrapping: true,
            viewportMargin: 10,
            foldGutter: true,
            gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
        });

        // 初始化输出格式编辑器
        window.outputFormatEditor = CodeMirror(document.getElementById('output-format-editor'), {
            value: `{{ output_format_content|safe }}`,
            mode: 'application/json',
            theme: 'monokai',
            lineNumbers: true,
            readOnly: true,
            lineWrapping: true,
            viewportMargin: 10,
            foldGutter: true,
            gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
        });
    });

</script>

<!-- CodeMirror 核心文件 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/codemirror.min.js"></script>

<!-- CodeMirror 折叠功能 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/fold/foldcode.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/fold/foldgutter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/fold/brace-fold.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/addon/fold/indent-fold.min.js"></script>

<!-- CodeMirror JSON模式 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.2/mode/javascript/javascript.min.js"></script>

{% endblock %}